//由消息提醒进入本页面

function messageUrl(){
    var mess = getHref().mess
    if(mess){
        if(mess=="ticketingOrderMessage"){//待出票
            $(".downBox").val("2");
            var urlRoot = url()
            getAjax(urlRoot);
        }
        if(mess=="connectAuditMessage"){//联运待审核
            conAduit();
        }
        if(mess=="upSeatAuditMessage"){//升舱待审核
            upSeatAduit();
        }
        if(mess=="addSeatAuditMessage"){//追位待审核
        	zhuiWeiAduit();
        }
    }else{
        var urlRoot = url()
        getAjax(urlRoot);
    }

}

function url(){
    var orderId = $(".orderNo").val();
    if(/\((.)+?\)/.test($(".dep").val())){//获取出发机场三字码
        var departure = $(".dep").val().slice(-5).split("(")[1].split(")")[0];
    }else{
        var departure = $(".dep").val()
    }
    if(/\((.)+?\)/.test($(".arr").val())){//获取到达机场三字码
        var arrival = $(".arr").val().slice(-5).split("(")[1].split(")")[0];
    }else{
        var arrival = $(".arr").val()
    }
    var departureDate = $(".depDate").val();
    var status = $(".downBox").val();
    
    var pageNum = $(".page").val()
    var pageSize = $(".pageSize").val()
    var urlRoot = "../order/find?orderId="+orderId+"&pageSize="+pageSize+"&pageNum="+pageNum+"&departure="+departure+"&arrival="+arrival+"&departureDate="+departureDate+"&status="+status+"&temp="+Math.random();
    return urlRoot;
}


$("#query").click(function(){
	$("input[type=radio]").attr("checked",false).parent().removeClass("checked");
    $(".page").val("1")
    $(".page").val("1");
    $(".pageSize").val("20");
    var urlRoot = url()
    getAjax(urlRoot);
})
$(".newright>span").click(function(){
	$(this).addClass("checked").siblings().removeClass("checked");
	$(this).find("input").prop("checked",true);
	$(this).siblings().find("input").prop("checked",false);
})
$(".conAduit").click(function(){
    conAduit()
})
//点击联运待审核
function conAduit(){
    $(".page").val("1");
    $(".pageSize").val("1000");
    var pageNum = $(".page").val();
    var pageSize = $(".pageSize").val();
    var urlRoot = "../order/findAuditConnectOrder?pageSize=1000&pageNum=1&temp="+Math.random();
    getAjax(urlRoot);
}
$(".upSeatAduit").click(function(){
    upSeatAduit()
})
//点击升舱待审核
function upSeatAduit(){
    $(".page").val("1");
    $(".pageSize").val("1000");
    var pageNum = $(".page").val();
    var pageSize = $(".pageSize").val();
    var urlRoot = "../order/findAuditExchOrder?pageSize=1000&pageNum=1&temp="+Math.random();
    getAjax(urlRoot);
}
$(".zhuiWei").click(function(){
	zhuiWeiAduit()
})
//点击追位待审核
function zhuiWeiAduit(){
    $(".page").val("1");
    $(".pageSize").val("1000");
    var pageNum = $(".page").val();
    var pageSize = $(".pageSize").val();
    var urlRoot = "../order/find?addSeat=1&pageSize=1000&pageNum=1&temp="+Math.random();
    getAjax(urlRoot);
}



/*———————————————————————————————————————查看详情—————————————————————————————————————————————*/

$('.tableData').delegate(".viewDetail","click",function(){
    var id=$(this).parent().prev().text();//获取当前订单状态的id值
    layer.open({
        type: 2,
        title:false,
        closeBtn: 0,
        title:false,
        shadeClose: true,
        shade: [0.9,'#cfcfcf'],
        area: ['98%', '98%'],
        content: ['../ak/embedDiv.html?id='+id],// iframe的url，no代表不显示滚动条
        end:function(){

        }

    });

})
/*———————————————————————————————————————订单号关联详情，点击订单号可查看详情—————————————————————————————————————————————*/

$('.tableData').delegate(".id_link","click",function(){
    var id=$(this).next().text();//获取当前订单状态的id值
    layer.open({
        type: 2,
        title:false,
        closeBtn: 0,
        title:false,
        shadeClose: true,
        shade: [0.9,'#cfcfcf'],
        area: ['98%', '98%'],
        content: ['../ak/embedDiv.html?id='+id],// iframe的url，no代表不显示滚动条
        end:function(){

        }

    });

})

/*———————————————————————————————————————更新票号—————————————————————————————————————————————*/
$('.tableData').delegate(".upOrder","click",function(){
    var id=$(this).parent().prev().text();//获取当前订单状态的id值
    layer.open({
        type: 2,
        title: ['更新票号','background-color:#6d6e72; color:#fff;font-size:14px;'],
        shadeClose: true,
        shade: [0.9,'#cfcfcf'],
        area: ['98%', '98%'],
        content: ['../ak/updateTicketNum.html?id='+id],// iframe的url，no代表不显示滚动条
        end:function(){
            getAjax();
        }

    });
})



//__________________________________________________________________________________封装ajax
var totalAmount
var totalPage
var nowPage
function getAjax(urlRoot){
	layer.load();
    if(urlRoot == undefined){
        urlRoot = url()
    }
    $.ajax({
        type:"get",
        //url:"../order/find?orderId="+orderId+"&pageSize="+pageSize+"&pageNum="+pageNum+"&departure="+departure+"&arrival="+arrival+"&departureDate="+departureDate+"&status="+status+"&temp="+Math.random(),
        url: urlRoot,
        dataType:"json",
        success:function(data){
        	layer.closeAll('loading');
            $(".clear").empty();
            totalAmount = data.data.total
            totalPage = data.data.pages
            nowPage = data.data.pageNum
            //共多少条
            $(".totalAmount").text(totalAmount)
            //共多少页
            $(".totalPage").text(totalPage)
            //第几页
            $(".nowPage").text(nowPage)
            var str = "";
            for(var i=0;i<data.data.list.length;i++){
                var len = data.data.list[i].itineraries.length;             
                for(var j=0;j<data.data.list[i].itineraries.length;j++){
                    if(j==0){
                    	var signStr = "<div class='signDiv'>";
                    	var singleSign = "";
                    	if(data.data.list[i].connect=="1"){
                    		signStr += "<label class='connectSign' title='联运'></label>"
                    	}                   	
                    	if(data.data.list[i].addSeat=="1"){
                    		signStr += "<label class='addSeatSign' title='追加'></label>"
                    	} 
                    	if(data.data.list[i].seatUp=="1"){
                    		signStr += "<label class='seatUpSign' title='升舱'></label>"
                    	}
                    	if(data.data.list[i].type=="3"){
                    		signStr += "<label class='SANKESign' title='散客'></label>"
                    	}
                    	if(data.data.list[i].single=="2"){
                    		singleSign += "<span class='singleProductSign'>单边</span>"
                    	}
                    	
                    	signStr += "</div>";
                    	 str+="<tr>" +
	                    	  "<td class='id_link' rowspan="+len+">"+signStr+data.data.list[i].id+singleSign+"</td>"+
	                    	  "<td rowspan="+len+" style=display:none;>"+data.data.list[i].id+"</td>"+
	                    	  "<td rowspan="+len+"><span style=color:#00aa98;>"+commomFun.toEmptyString(data.data.list[i].purchaseName)+"</span></br>"+data.data.list[i].customer+"</td>"                   	
                    }

	                   
                    
	                    str+="<td>"+data.data.list[i].itineraries[j].flightNumber+"</td>"+
	                         "<td>"+data.data.list[i].itineraries[j].departureAirport+" ("+data.data.list[i].itineraries[j].departureAirportCode+") <span style='color:red;'>"+data.data.list[i].itineraries[j].departureAirportTerminal+"</span></br><span style=color:#00aa98;>"+data.data.list[i].itineraries[j].departureDate+"&nbsp;&nbsp;"+data.data.list[i].itineraries[j].departureTime+"</span></td>"+
	                         "<td>"+data.data.list[i].itineraries[j].arriveAirport+" ("+data.data.list[i].itineraries[j].arriveAirportCode+") <span style='color:red;'>"+data.data.list[i].itineraries[j].arriveAirportTerminal+"</span></br><span style=color:#00aa98;>"+data.data.list[i].itineraries[j].arriveAirportDate+"&nbsp;&nbsp;"+ data.data.list[i].itineraries[j].arriveAirportTime+"</span></td>"
                    if(j==0){
                        str+="<td rowspan="+len+">"+commomFun.cabinStatusStr(data.data.list[i].itineraries[j].seatClass)+"</td>"+
                             "<td rowspan="+len+"><span style=color:#ff7777;>"+data.data.list[i].realPassengerTotal+"</span>/"+data.data.list[i].passengerTotal+"</td>"+
                             "<td rowspan="+len+">"+commomFun.orderStatusStr(data.data.list[i].status)+"</td>"+
                             "<td rowspan="+len+" style=display:none;>"+data.data.list[i].id+"</td>"
                             //"<td class=doStr rowspan="+len+">"+doStr+"</td>"

                    }
                    str+="</tr>"

                }

            }
            $(".clear").append(str)
        }
    })
}

//____________________________________________出发到达机场条件互换________________
$(".exchangeAirportCode").click(function(){
    var exchangeVar = $(".queryDep").val();
    $(".queryDep").val($(".queryArr").val());
    $(".queryArr").val(exchangeVar);
})
//________________________________________表头固定____________________________________________
$("#dataTable").freezeHeader();
//________________________________________分页__________________________________
$(".Pagination").load("Pagination.html",function(){
    messageUrl()
})
//_________________________________________________________________________机场三字吗联想
var autocompleteData=[];
$.ajax({
    type:"get",
    url:"../Airapt?pageSize=100000&pageNum=1&temp="+Math.random(),
    dataType:"json",
    success:function(data){
        autocompleteData = data.data.list;
        $('.autocomplete').autocomplete({
            lookup: autocompleteData,
            autoSelectFirst:true,
            onSelect: function (suggestion) {
            }
        });
    }
})

